<template>
    <!-- 租赁房产管理 -->
    <base-breadcrumb :title="$route.meta.title">
        <a-row :gutter="10" class="page-height">
            <!-- 树搜索 -->
            <a-col :span="6">
                <a-card class="page-height-tree">
                    <title-name title="工会组织"></title-name>
                    <!-- 公司组织树搜索 -->
                    <tree-union
                        ref="treeOrganization"
                        @loader="getTable"
                        :expandByAuto="true"
                        :selectOptions.sync="selectOptions"
                        :showChildWithSearch="true"
                        :istakeOutHight="true"
                    />
                </a-card>
            </a-col>
            <a-col :span="18" class="page-height-list-wrapper">
                <!-- 搜索 -->
                <searchData :searchData="searchArr" @search="search"></searchData>
                <!-- 表格 -->

                <a-card :bordered="false"  class="page-height-list">
                    <!-- <title-name title="组织信息列表"></title-name> -->
                    <a-button
                        class="mb12"
                        icon="plus"
                        type="primary"
                        @click="handleManage(2)"
                        v-btnPermission="'lu_001_add_01'"
                        >新增</a-button
                    >
                    <!-- 表格 -->
                    <list-table
                        ref="table"
                        tableLayout="fixed"
                        size="default"
                        rowKey="id"
                        :columns="columns"
                        :request="loadData"
                        :alert="true"
                        show-size-changer
                        show-quick-jumper
                        showPagination="auto"
                    >
                        <span slot="auditStatus" slot-scope="text, record">
                            <list-status
                                :status="record.auditStatus"
                                :isApproval="true"
                                conversion="en"
                                :text="text"
                            ></list-status>
                        </span>
                        <template slot="action" slot-scope="text, record">
                            <MoreButton>
                            <a v-if="record.auditStatus == 'REVOKE'" @click="handleManage(0, record)">查看</a>
                            <template v-else>
                                <a @click="handleManage(0, record)">查看</a>

                                <a
                                    v-btnPermission="'lu_001_edi_02'"
                                    @click="handleManage(1, record)"
                                    v-if="record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED'"
                                    >编辑</a
                                >
                                <a
                                    class="del_btn"
                                    @click="handleRemove(record.id)"
                                    v-if="record.auditStatus == 'DRAFT'"
                                    v-btnPermission="'lu_001_del_03'"
                                    >删除</a
                                >
                                <a
                                    class="del_btn"
                                    @click="handleUndo(record.id)"
                                    v-if="record.auditStatus == 'PAST'"
                                    v-btnPermission="'lu_001_cxo_05'"
                                    >撤销</a
                                >

                                <!-- 添加管理人员 -->
                                <span v-if="record.auditStatus == 'PAST'" v-btnPermission="'lu_001_edi_02'">
                                    <a @click="handleManage(0, record, 'true')">编辑</a>
                                </span>

                                <span
                                    v-btnPermission="'lu_001_loo_04'"
                                    v-show="record.parentId != 0"
                                    v-if="
                                        record.auditStatus === 'PAST' ||
                                        record.auditStatus === 'SUBMITTED' ||
                                        record.auditStatus === 'REJECTED' ||
                                        record.auditStatus === 'REVOKEIN' ||
                                        record.auditStatus === 'REVOKE'
                                    "
                                >
                                    <approval-button
                                        :status="record.auditStatus"
                                        :id="record.id"
                                        text="审批信息"
                                    ></approval-button>
                                </span>
                            </template>
                            </MoreButton>
                        </template>
                    </list-table>
                </a-card>
            </a-col>
        </a-row>
    </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import {
    getPageUnionOrganization,
    removePageUnionOrganization,
    undoPageUnionOrganization
} from '@/api/union/organizationManagement' // api
import TreeSelectOrganization from '@/components/TreeSelectOrganization'
import Selector from '@/components/Select/Selector'
import BasePage from '@/views/basePage' // 基础配置
import SelectHierarchy from '@/components/Select/SelectHierarchy'
import TreeUnion from '@/components/businessComponents/TreeUnion' // 树
const searchArr = [
    // 搜索框
    {
        name: '组织名称',
        type: 'input',
        value: 'unionOrgName'
    },
    {
        name: '所属层级',
        valueKey: 'unionLevelId',
        type: Selector,
        selectType: '1',
        urlType: 'union'
    }
]
const columns = [
    {
        title: '序号',
        width: 80,
        dataIndex: 'index',
        customRender() {
            return arguments[2] + 1
        }
    },
    {
        title: '组织名称',

        dataIndex: 'unionOrgName'
    },
    {
        title: '层级',
        ellipsis: true,
        dataIndex: 'unionLevelName'
    },
    {
        title: '工会主席',
        ellipsis: true,
        dataIndex: 'unionChairmanName'
    },
    {
        title: '成立时间',
        ellipsis: true,
        dataIndex: 'unionEstDate'
    },
    {
        title: '会员人数',
        ellipsis: true,
        dataIndex: 'unionVipNum'
    },
    {
        title: '审核状态',
        dataIndex: 'auditStatus',
        ellipsis: true,
        scopedSlots: { customRender: 'auditStatus' }
    },
    {
        title: '操作',
        dataIndex: 'action',
        width: '180px',
        align: 'center',
        scopedSlots: { customRender: 'action' }
    }
]
export default {
    name: 'a' + Date.now(),
    extends: new BasePage(),
    components: {
        STable,
        TreeUnion
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {}, // 查询参数
            selectOptions: {}, // 选中节点对象
            loadData: (parameter) => {
                const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
                return getPageUnionOrganization(requestParameters).then((res) => {
                    console.log(res)
                    return res
                })
            }, // 加载数据方法 必须为 Promise 对象
            removeApi: { remove: removePageUnionOrganization }, // api

            form: {}
        }
    },
    mounted() {
        this.$refs.treeOrganization.getList().then((res) => {
            this.$refs.table.refresh(true)
        })
    },
    methods: {
        // 搜索
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        getTable(value) {
            this.queryParam.id = this.selectOptions.id
            this.queryParam.parentId = this.selectOptions.id
            this.$refs.table.refresh(true)
        },
        /**
         * 撤销草稿:api 请求api;params 请求参数
         */
        handleUndo(id) {
            this.$confirm({
                title: '温馨提示',
                content: '请确定是否要撤销该条数据？',
                onOk: () => {
                    return undoPageUnionOrganization({
                        id
                    }).then(() => {
                        this.$message.success('撤销成功！')
                        this.$refs.table.loadData()
                    })
                }
            })
        },
        // 操作栏
        handleManage(type, record, addpersion = 'false') {
            this.editModel = type
            let query = {
                editModel: type,
                addpersion: addpersion
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: '/union/organizationManagement/organizationalStructure/updateOrganizationalStructure',
                query
            })
        }
    }
}
</script>
